limsOrderTask.editPage = {

    // 样本信息
    getTaskGrid : function() {
        var _this = this;
        return {
            type : 'grid',
            id : _this.idManager.sampleGridId,
            service : 'limsOrderTaskServiceImpl',
            dbTable : 'T_LIMS_ORDER_TASK',
            page: true,
            columns : limsOrderTask.getEditListColumns(),
            toolbar : [{
                type : 'form',
                id : _this.idManager.testSelectFormId,
                columns : 1,
                fields : [{
                    field : 'testId',
                    title : 'T_LIMS_TEST.TESTNAME',
                    type : 'select',
                    // category : 'orderTask-Test',
                    search : true,
/*                    param : {
                        status : 'draft'
                    },*/
                    firstBlank: false,
                    refreshGrid : false,
                    onChange: function (field, value, index, oldValue, text) {
                        _this.loadTestSampleInfo(value);
                        if (value && value !== ''){
                            Gikam.getAsyncComp(_this.idManager.runGridId).done(function(grid) {
                                grid.refresh({
                                    url : limsOrderTask.runUrl + '/queries/raw',
                                    requestData : {
                                        status_EQ: 'draft',
                                        testId_EQ: value
                                    }
                                })
                            })
                        }else {
                            Gikam.getAsyncComp(_this.idManager.runGridId).done(function(grid) {
                                grid.refresh({
                                    url : limsOrderTask.runUrl + '/queries/raw',
                                    requestData : {
                                        status_EQ: 'draft',
                                        testId_EQ: -1
                                    }
                                })
                            });
                        }
                    },
                    onBeforeSelect: function (value, rowIndex) {
                        let url = limsOrderTask.baseUrl + '/select/test-selections' + Gikam.param({status: 'draft'})
                        var items = []
                        Gikam.getTextSync(url).done(rows => {
                            rows = JSON.parse(rows)
                            items = rows.map(r => {
                                return {
                                    text: r.testName,
                                    value: r.testId
                                }
                            })
                        })
                        return items
                    }
                }]
            }, {
                type: 'button',
                text: 'T_LIMS_SAMPLE.SAMPLECODE',
                icon: 'select',
                onClick: function () {
                    var testForm = Gikam.getComp(_this.idManager.testSelectFormId);
                    if(Gikam.isEmpty(testForm.getData().testId)){
                        Gikam.alert('TASK.TIP.CHOOSE_TEST');
                        return;
                    }
                    var mainGrid = Gikam.getComp(_this.idManager.sampleGridId)
                    Gikam.createLimsModal({
                        title: 'T_CORE_CHART.SEARCHRULE',
                        height: '300',
                        width: '400',
                        onConfirm: function () {
                            var form = Gikam.getComp('sampleCode-form');
                            var data = form.getData();
                            if (Gikam.isEmpty(data)) {
                                return;
                            }
                            Gikam.postText(limsOrderTask.baseUrl + '/queries/raw', Gikam.getJsonWrapper({
                                f: {
                                    sampleCode_IN: data.sampleCode.replace(/[(\r\n)|(\ +)|(，)|(；)|(;)]/g, ','),
                                    status_EQ: 'draft',
                                    testId_EQ: testForm.getData().testId,
                                    addInRun_EQ: '0',
                                    flag_EQ: '1'
                                },
                                n : -1
                            })).done(function (data) {
                                data = JSON.parse(data)
                                mainGrid.loadData(data.rows)
                            }).always(function () {
                                Gikam.getLastModal().close();
                            });
                        },
                        m : {
                            type: 'form',
                            id: 'sampleCode-form',
                            columns: 1,
                            titleWidth: 120,
                            fields: [{
                                field: 'sampleCode',
                                title: 'T_LIMS_SAMPLE.SAMPLECODE',
                                type: 'textarea',
                                colspan: 2,
                                height: 180,
                            }],
                        }
                    })
                }
            }]
        }
    },

    loadTestSampleInfo: function(value) {
        var _this = this;
        if (value && value !== ''){
            Gikam.getAsyncComp(_this.idManager.sampleGridId).done(function(grid) {
                let requestParam = {
                    status_EQ: 'draft',
                    testId_EQ: value,
                    addInRun_EQ: '0',
                    flag_EQ: '1'
                };
                grid.setOptions({
                    url : limsOrderTask.baseUrl + '/supplement/queries',
                    requestData : requestParam
                });
                _this.refreshGridColumns(grid, requestParam, limsOrderTask.getEditListColumns());
                grid.refresh();
            });
        }else {
            Gikam.getAsyncComp(_this.idManager.sampleGridId).done(function(grid) {
                grid.cleanData();
                grid.options.columns = limsOrderTask.getEditListColumns();
                grid.refreshColumns(limsOrderTask.getEditListColumns());
            });
        }
    },

    //批次信息
    getRunGrid : function() {
        var _this = this;
        return {
            type : 'grid',
            id : _this.idManager.runGridId,
            service : 'limsRunServiceImpl',
            dbTable : 'T_LIMS_RUN',
            // page: true,
            columns : limsOrderTask.getRunListColumns(),
            onLoadSuccess : function(data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                    _this.loadRunDetail();
                }
            },
            requestData: {
                createdById_EQ: workspace.user.id,
            },
            onRowActive : function(index, row) {
                _this.loadRunDetail(row);
            },
            toolbar : [ {
                type: 'button',
                text: 'T_LIMS_ORDER_TASK.BUTTON.CREATE_RUN',
                icon: 'select',
                onClick : function() {
                    _this.addRun();
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.DELETE',
                icon: 'remove-row',
                onClick : function() {
                    _this.delRun();
                }
            }, {
                type: 'button',
                text: 'T_LIMS_ORDER_TASK.BUTTON.ASSIGNMENT',
                icon: 'select',
                onClick : function() {
                    _this.batchChooseAssignment();
                }
            }, {
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                icon: 'submit', color: 'success',
                onClick : function() {
                    _this.submit();
                }
            },{
                type: 'button',
                text: 'GIKAM.BUTTON.EXPORTRUNBOARDHOLE',
                icon: 'export',
                onClick: function () {
                    _this.exportRunBoardHoleExcel();
                }
            }/*,{
                type : 'button',
                text : 'GIKAM.BUTTON.IMPORTRUNBOARDHOLE',
                icon : 'export',
                onClick : function () {
                    _this.importRunBoardHoleInfo();
                }
            } */]
        }
    },

    // 导出板孔信息
    exportRunBoardHoleExcel: function () {
        var _this = this;
        let activedRow = Gikam.getComp(_this.idManager.runGridId).getActivedRow();
        if (Gikam.isEmpty(activedRow)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }

        Gikam.getText(IFM_CONTEXT + '/core/module/item/files/template-urls' + Gikam.param({
            templateCode: 'LimsRunBoardHoleExportTemplate',
            service: 'LimsRunBoardHoleExportTemplate',
            id: activedRow.id
        })).done(function (url) {
            Gikam.download(url);
        })
    },

    // 导入板孔信息
    importRunBoardHoleInfo : function(){
        var _this = this;
        var grid = Gikam.getComp(_this.idManager.runGridId);
        var activedRow = grid.getActivedRow();
        if (Gikam.isEmpty(activedRow)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }
        Gikam.create('simpleUploader',{
            id : 'question-info-uploader',
            dbTable: 'T_LIMS_RUN',
            bizId: 'self',
            autoClose: true,
            multiple: false,
            accept : ['xls'],
            onAfterClose: function (fields) {
                if (Gikam.isNotEmpty(fields)) {
                    workspace.window.showMask();
                    var url = Gikam.printf(IFM_CONTEXT + '/core/module/item/files/{id}/action/import/' + 'limsRunBoardHoleImportFileFunction', {
                        id: fields[0].id
                    }) + Gikam.param({
                        runCode : activedRow.runCode
                    });
                    Gikam.post(url).done(function () {
                        Gikam.getComp(_this.idManager.sampleGridId).refresh();
                        grid.refresh();
                    }).always(function () {
                        workspace.window.closeMask();
                    });
                }
            }
        })
    },

    // 添加批次
    addRun : function(){
        let _this = this;
        let testId = Gikam.getComp(_this.idManager.testSelectFormId).getData().testId;
        if(Gikam.isEmpty(testId)){
            Gikam.alert('TASK.TIP.CHOOSE_TEST');
            return;
        }
        Gikam.preInsert({
            modalTitle: 'GIKAM.BUTTON.INSERT',
            fields: limsOrderTask.getRunBoardFormFields(),
            titleWidth: 80,
            url: limsOrderTask.baseUrl + '/run/create',
            disableNotEmptyValidate: true,
            param : {
                testId : testId
            }
        }).done(function () {
            Gikam.getComp(_this.idManager.runGridId).refresh();
        });
    },

    // 删除批次
    delRun : function(){
        var _this = this;
        let grid = Gikam.getComp(_this.idManager.runGridId);
        let selections = grid.getSelections();
        if (Gikam.isEmpty(selections)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
            return;
        }
        workspace.window.showMask();
        Gikam.postText(limsOrderTask.baseUrl + '/run/delete',
            Gikam.getJsonWrapper(null, [null, selections])).done(function () {
            grid.refresh();
            _this.loadTestSampleInfo(Gikam.getComp(_this.idManager.testSelectFormId).getField('testId').value);
        }).always(function () {
            workspace.window.closeMask();
        });
    },

    // 任务分配
    batchChooseAssignment: function () {
        var _this = this;
        var runListGrid = Gikam.getComp(_this.idManager.runGridId);
        var selections = runListGrid.getSelections();
        if (Gikam.isEmpty(selections)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }
        var testerIds = '';
        Gikam.getJsonSync(Gikam.printf(IFM_CONTEXT + '/secure/basemodule/coredata/tests/{id}', {
            id: selections[0].testId
        })).done(function (data) {
            testerIds = data.testerId
        });

        Gikam.create('modal', {
            width: 350,
            height: 300,
            title: 'T_LIMS_ORDER_TASK.BUTTON.ASSIGNMENT',
            url: limsOrderTask.baseUrl + '/page/assignment/detail' + Gikam.param({
                testId: selections[0].testId,
                testerIds: testerIds
            }),
            onAfterClose: function (data) {
                if (Gikam.isNotEmpty(data)) {
                    workspace.window.showMask();
                    Gikam.postText(limsOrderTask.baseUrl + '/action/batch-save-assignment',
                        Gikam.getJsonWrapper(data, [null, selections])).done(function (result) {
                            runListGrid.refresh();
                    }).always(function () {
                        workspace.window.closeMask();
                    });
                }
            }
        });
    },

    // 提交
    submit: function () {
        var _this = this;
        var runListGrid = Gikam.getComp(_this.idManager.runGridId);
        var selections = runListGrid.getSelections();
        if (Gikam.isEmpty(selections)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }
        if(runListGrid.validate(selections)) {
            Gikam.confirm('GIKAM.MODAL.SUBMIT', 'GIKAM.TIP.SUBMIT', function () {
                workspace.window.showMask();
                Gikam.postText(limsOrderTask.baseUrl + '/submit',
                    Gikam.getJsonWrapper(null, [null, selections])).done(function (result) {
                    runListGrid.refresh();
                }).always(function () {
                    workspace.window.closeMask();
                });
            })
        }
    },

    // 布板信息
    boardTab : function(){
        let _this = this;
        return{
            type : 'layout',
            north : {
                height : 46,
                items : [{
                    id : _this.idManager.runBoardDetailFormId,
                    type : 'form',
                    columns : 3,
                    titleWidth : 70,
                    titleAlign : true,
                    style : {
                        margin : '4px',
                        padding : '4px'
                    },
                    fields : [{
                        field: 'sampleCode',
                        refreshGrid: false,
                        inputWidth: 150,
                        width: 260,
                        title: 'T_LIMS_SAMPLE.SAMPLECODE',
                        onKeyDown: function (keyCode, value) {
                            _this.saoMaAssignLocation(keyCode,value);
                        }
                    }, {
                        field: 'startHole',
                        title: 'T_LIMS_LOCATION.STARTHOLE',
                        refreshGrid: false,
                        inputWidth: 160,
                        width: 260,
                        placeholder: '格式:字母加数字(如:A01)',// 未生效,
                    },{
                        field: 'assignType',
                        title: 'T_LIMS_LOCATION.ASSIGNTYPE',
                        refreshGrid: false,
                        type: 'select',
                        firstBlank: false,
                        inputWidth : 70,
                        width: 170,
                        category: 'sys',
                        param: {
                            codeCategoryId: 'assignType'
                        },
                        value: 'x',
                        onChange: function (field, value) {
                            this.setData({
                                startHole: ''
                            })
                        }
                    }]
                }]
            },
            center : {
                items : [{
                    type : 'iframe',
                    src : '/static/basemodule/business/run-board/index.html',
                    id : 'ksh-run-board-iframe'
                }]
            }
        }
    },

    // 样本扫码
    saoMaAssignLocation : function(keyCode, value){
        let _this = this;
        if (keyCode != '13') {
            return;
        }
        let activeRow = Gikam.getComp(_this.idManager.runGridId).getActivedRow();
        if (Gikam.isEmpty(activeRow)) {
            return;
        }
        if (activeRow.freeCount <= 0) {
            Gikam.alert('FREECOUNT.LITTTLE.ZORE');
            return;
        }

        let startHole = Gikam.getComp(_this.idManager.runBoardDetailFormId).getData().startHole;
        let row = 1;
        let col = 1;
        if (!Gikam.isEmpty(startHole)) {
            // 校验孔位是否满足格式
            let regex = "^[a-zA-Z][0-9]+$";
            if (!startHole.match(regex)) {
                Gikam.alert('STARTHOLE.FORMATTER.ERROR');
                return;
            }
            // 校验输入孔位是否正确
            let rowNum = activeRow.rowNum;
            let columnNum = activeRow.columnNum;
            row = startHole.toUpperCase().charCodeAt(0) - 64;
            col = startHole.substring(1).replace(/\b(0+)/gi, "");
            if (row > rowNum || parseInt(col) > columnNum) {
                Gikam.alert('INPUT.STARTHOLE.NOT.EXISTS');
                return;
            }
        }
        let testForm = Gikam.getComp(_this.idManager.testSelectFormId);
        if(Gikam.isEmpty(testForm.getData().testId)){
            Gikam.alert('TASK.TIP.CHOOSE_TEST');
            return;
        }
        let assignType = Gikam.getComp(_this.idManager.runBoardDetailFormId).getData().assignType;
        Gikam.postSync(limsOrderTask.baseUrl + '/queries',Gikam.getJsonWrapper({
            f : {
                sampleCode_EQ : value,
                status_EQ: 'draft',
                runId : activeRow.id,
                testId_EQ : testForm.getData().testId,
                flag_EQ : '1'
            },n : -1,s : -1
        })).done(function (data) {
            if (data.total === 0){
                Gikam.alert('T_LIMS_LOCATION_BOARD.ASSIGN.NO_SAMPLE');
            } else if (Gikam.isNotEmpty(data.rows[0].boardHoleId)){
                Gikam.alert('T_LIMS_LOCATION_BOARD.ASSIGN.SAMPLE_ASSIGNABLE');
            }else{
                workspace.window.showMask();
                Gikam.postText(limsOrderTask.boardUrl + '/update-samples-batch',
                    Gikam.getJsonWrapper({
                        assignType: assignType,
                        row: row,
                        col: col
                    }, [null, [activeRow]], [null, data.rows])).done(function (message) {
                    if (message !== 'success') {
                        Gikam.alert(message);
                        return;
                    }
                    Gikam.getComp(_this.idManager.runGridId).refreshRowById(activeRow.id);
                    _this.loadTestSampleInfo(Gikam.getComp(_this.idManager.testSelectFormId).getField('testId').value);
                    _this.loadRunSampleDetail(activeRow);
                    _this.loadRunBoardDetail(activeRow);
                }).always(function () {
                    let searchForm = Gikam.getComp(_this.idManager.runBoardDetailFormId);
                    searchForm.setData({
                        sampleCode: '',
                    });
                    workspace.window.closeMask();
                });
            }
        });
    },

    // 加载布板信息
    loadRunBoardDetail : function(row){
        let _this = this;
        if (row){
            Gikam.postSync(limsOrderTask.boardHoleUrl + '/queries', Gikam.getJsonWrapper({
                f: {
                    boardId_EQ: row.id
                },
                o: [{
                    y : 'asc'
                },{
                    x : 'asc'
                }],
                n: -1, s: -1
            })).done(function (data) {
                const  dom=document.querySelector("#ksh-run-board-iframe >iframe");
                let flag=false;  //是否初次加载
                dom.onload=function(){
                    flag =true;
                    dom.contentWindow.postMessage({
                        type:1,
                        data: data.rows
                    }, "*");
                };
                if(!flag){
                    dom.contentWindow.postMessage({
                        type:1,
                        data: data.rows
                    }, "*");
                }
            });
        }else{
            const  dom=document.querySelector("#ksh-run-board-iframe >iframe");
            if (Gikam.isEmpty(dom)) return;
            let flag=false;  //是否初次加载
            dom.onload=function(){
                flag =true;
                dom.contentWindow.postMessage({
                    type:1,
                    data: []
                }, "*");
            };
            if(!flag){
                dom.contentWindow.postMessage({
                    type:1,
                    data: []
                }, "*");
            }
        }
    },

    // 批次激活加载信息
    loadRunDetail : function(row){
        var _this = this;

        // 加载批次详情
        _this.loadRunSampleDetail(row);

        // 布板信息
        _this.loadRunBoardDetail(row);

        // 附件信息
        Gikam.getAsyncComp(_this.idManager.uploaderId).done(function (grid) {
            if (row) {
                grid.setOptions({
                    bizId: row.runCode
                })
            } else {
                grid.setOptions({
                    bizId: -9
                })
            }
        });
    },

    loadRunSampleDetail: function(row) {
        var _this = this;
        Gikam.getAsyncComp(_this.idManager.runDetailGridId).done(function(grid) {
            if (row){
                let requestParam = {
                    status_EQ: 'draft',
                    runId_EQ: row.id,
                    flag_EQ: '1'
                };
                grid.setOptions({
                    url : limsOrderTask.baseUrl + '/supplement/queries',
                    requestData : requestParam
                });
                _this.refreshGridColumns(grid, requestParam, limsOrderTask.getRunTaskListColumns());
                grid.refresh();
            }else{
                grid.cleanData();
                grid.options.columns = limsOrderTask.getRunTaskListColumns();
                grid.refreshColumns(limsOrderTask.getRunTaskListColumns());
            }
        });
    },

    // 加载补充信息列
    refreshGridColumns: function (grid, requestParam, columns) {
        var _this = this;
        let url = limsOrderTask.orderTaskSupplementUrl + '/r/supplement-to-columns/queries';
        Gikam.postSync(url, Gikam.getJsonWrapper({f: requestParam})).done(function (data) {
            if (Gikam.isNotEmpty(data)) {
                Gikam.each(data.rows, function (index, item) {
                    var fieldName = item.fieldName;
                    columns.push({
                        field: 'ext$.' + fieldName,
                        title: item.unit ? fieldName + '('+ item.unit +')' : fieldName,
                        validators: (item.requiredFlag === '1' || item.requiredflag === '1') ? ['notEmpty']:null,
                        // editor : true,
                        width: 120,
                        sort: false,
                        autoSave: false,
                        onChange: function (field, value, index) {
                            _this.saveSupplementValue(fieldName, value, this.getData()[index].id, function () {
                                grid.refreshRowByIndex(index);
                            });
                        },
                        onBeforeEditorRender: function (row) {
                            return row.ext$.supplementinfo && eval('(' + row.ext$.supplementinfo + ')').hasOwnProperty(fieldName);
                        },
                        styleFormatter: function (row) {
                            return {
                                // backgroundColor: (row.ext$.supplementinfo && eval('(' + row.ext$.supplementinfo + ')')[fieldName])? '#7CFC00': null
                            }
                        }
                    });
                });
            }
        });
        grid.cleanData();
        grid.options.columns = columns;
        grid.refreshColumns(columns);
    },

    saveSupplementValue: function (fieldName, value, orderTaskId, callback) {
        var url = Gikam.printf(limsOrderTask.orderTaskSupplementUrl + '/{orderTaskId}/update/supplement', {
            orderTaskId: orderTaskId
        });
        workspace.window.showMask();
        Gikam.postText(url, Gikam.getJsonWrapper(null, [null, [{
            fieldValue: value,
            fieldName: fieldName

        }]])).done(function (data) {
            callback && callback();
        }).always(function () {
            workspace.window.closeMask();
        });
    },

    getTabParam : function(){
        let _this = this;
        return{
            type : 'tab',
            id : 'run-order-task-detail-tab',
            panels : [{
                title : 'T_LIMS_ORDER_TASK.TITLE.RUN_DETIAL', // 批次详情
                items : [_this.getTabInfo()]
            },{
                title : 'T_LIMS_ORDER_TASK.TITLE.BOARD', // 布板信息
                items : [this.boardTab()]
            },{
                title : 'GIKAM.FILE.ATTACHMENT', // 附件
                items : [_this.getDetailAttachment()]
            }]
        }
    },

    // 附件
    getDetailAttachment : function(){
        let _this = this;
        return{
            type: 'uploader',
            id: _this.idManager.uploaderId,
            filter: false,
            dbTable: 'T_LIMS_RUN',
            onBeforeUpload: function () {
                var selection = Gikam.getComp(_this.idManager.runGridId).getSelections();
                if (!selection || Gikam.isEmpty(selection)) {
                    Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM', 200);
                    return false;
                }
            },
            onBeforeDelete: function () {
                let grid = this.grid;
                let selections = grid.getSelections();
                if (Gikam.isEmpty(selections)) {
                    Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                    return false;
                }
                let bool = selections.filter(item => item.bizCategory === 'result');
                if (bool.length > 0){
                    Gikam.alert('NO.DELETE.FJTYPE.OF.RESULT');
                    return false;
                }
            },
            formatterGridColumns: function (columns) {
                columns.splice(2, 0, {
                    field: 'bizCategory',
                    title: 'LIMS.MODLE.FILE.FILETYPE',
                    type: 'select',
                    width: 140,
                    category: 'sys',
                    param: {
                        codeCategoryId: 'fjType'
                    }
                });
                return Gikam.getFormatterGridColumns(columns,true);
            },
            onBeforeFilesUpload : function (files) {
                files.map(file => file.bizCategory = 'dispatch');
                return true;
            }
        }
    },

    getTabInfo : function() {
        var _this = this;
        return {
            type : 'grid',
            id : _this.idManager.runDetailGridId,
            service : 'limsOrderTaskServiceImpl',
            dbTable : 'T_LIMS_ORDER_TASK',
            // page: true,
            columns : limsOrderTask.getRunTaskListColumns(),
            toolbar : [ {
                type: 'button',
                text: 'T_LIMS_ORDER_TASK.BUTTON.ADD_IN_RUN',
                icon: 'add',
                onClick : function() {
                    _this.addToRun();
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.DELETE',
                icon: 'remove-row',
                onClick : function() {
                    _this.removeFromRun();
                }
            },{
                type: 'button',
                text: 'T_LIMS_ORDER_TASK.BUTTON.ADD_QC',
                icon: 'select',
                onClick : function() {
                    _this.addQcSample();
                }
            }, {
                type: 'button',
                text: 'T_LIMS_ORDER_TASK.BUTTON.DELETE_QC',
                icon: 'remove-row',
                onClick : function() {
                    _this.deleteQcSample();
                }
            }]
        }
    },

    addQcSample: function () {
        var _this = this;
        var taskRun = Gikam.getComp(_this.idManager.runGridId).getActivedRow();
        if (Gikam.isEmpty(taskRun)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }
        Gikam.create('modal', {
            title: Gikam.choose.getConfig("zk-sample-choose").title,
            url: IFM_CONTEXT + Gikam.choose.getConfig("zk-sample-choose").url + Gikam.param({
                single: true,
                firstTestId: taskRun.testId
            }),
            onAfterClose: function (rows) {
                if (Gikam.isEmpty(rows)) {
                    return;
                }
                var url = limsOrderTask.folderUrl + '/add/qc/sample';
                workspace.window.showMask(true);
                Gikam.postText(url, Gikam.getJsonWrapper({
                    runId: taskRun.id,
                    runCode: taskRun.runCode,
                    firstTestId: taskRun.testId
                }, [null, rows])).done(function (data) {
                    workspace.window.closeMask();
                    Gikam.getComp(_this.idManager.runDetailGridId).refresh();
                }).always(function () {
                    workspace.window.closeMask();
                })
            }

        });
    },

    deleteQcSample: function () {
        var _this = this;
        var grid = Gikam.getComp(_this.idManager.runGridId);
        var row = grid.getActivedRow();
        var selections = Gikam.getComp(_this.idManager.runDetailGridId).getSelections();
        if (Gikam.isEmpty(selections)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }
        for (let i = 0; i < selections.length; i++) {
            if (selections[i].sampleCode.indexOf('QC') === -1) {
                Gikam.alert('MODULE.BUSINESS.ORDERTASK.VALIDATOR.DELETE_QC_SAMPLE');
                return;
            }
        }
        Gikam.confirm('GIKAM.BUTTON.CONFIRM', 'GIKAM.TIP.CONFIRM_TO_DELETE', function () {
            var url = limsOrderTask.folderUrl + '/delete/qc/sample';
            workspace.window.showMask(true);
            Gikam.postText(url, Gikam.getJsonWrapper(null, [null, selections])).done(function (data) {
                workspace.window.closeMask();
                _this.loadRunBoardDetail(row);
                grid.refreshRowById(row.id);
                Gikam.getComp(_this.idManager.runDetailGridId).refresh();
            }).always(function () {
                workspace.window.closeMask();
            })
        })
    },

    // 添加到批
    addToRun : function(){
        var _this = this;
        let grid = Gikam.getComp(_this.idManager.sampleGridId);
        let selections = grid.getSelections();
        if (Gikam.isEmpty(selections)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
            return;
        }
        let activedRow = Gikam.getComp(_this.idManager.runGridId).getActivedRow();
        if (Gikam.isEmpty(activedRow)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
            return;
        }
        workspace.window.showMask();
        Gikam.postText(limsOrderTask.baseUrl + '/run/add/tasks',
            Gikam.getJsonWrapper({
                runId : activedRow.id,
                runCode : activedRow.runCode
            }, [null, selections])).done(function () {
                _this.loadTestSampleInfo(Gikam.getComp(_this.idManager.testSelectFormId).getField('testId').value);
                _this.loadRunSampleDetail(activedRow);
        }).always(function () {
            workspace.window.closeMask();
        });
    },

    // 删除
    removeFromRun : function(){
        let _this = this;
        let grid = Gikam.getComp(_this.idManager.runGridId);
        let row = grid.getActivedRow();
        let selections = Gikam.getComp(_this.idManager.runDetailGridId).getSelections();
        if (Gikam.isEmpty(selections)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
            return;
        }
        workspace.window.showMask();
        Gikam.postText(limsOrderTask.baseUrl + '/run/remove/tasks',
            Gikam.getJsonWrapper(null, [null, selections])).done(function () {
            _this.loadTestSampleInfo(Gikam.getComp(_this.idManager.testSelectFormId).getField('testId').value);
            _this.loadRunSampleDetail(row);
            _this.loadRunBoardDetail(row);
            grid.refreshRowById(row.id);
        }).always(function () {
            workspace.window.closeMask();
        });
    },

    idManager : {
        layoutId : 'lims-order-task-edit-list-layout',
        sampleGridId : 'lims-order-task-sample-list-grid',
        testSelectFormId : 'order-task-test-form',
        runGridId : 'lims-run-board-list-grid',
        runDetailGridId : 'lims-run-order-task-edit-list-grid',
        uploaderId : 'task-run-uploader',
        runBoardDetailFormId : 'run-board-detail-form',
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : _this.idManager.layoutId,
            renderTo : workspace.window.$dom,
            center : {
                items : [ {
                    type : 'layout',
                    north : {
                        height : '50%',
                        title : 'T_LIMS_ORDER_TASK.TITLE.SAMPLE', // 样本信息
                        items: [_this.getTaskGrid()]
                    },
                    center : {
                        items : [{
                            type : 'layout',
                            west : {
                                width : '40%',
                                title : 'T_LIMS_ORDER_TASK.TITLE.RUN',
                                items: [this.getRunGrid()]
                            },
                            center : {
                                items : [this.getTabParam()]
                            }
                        }]
                    }
                } ]
            },
        });
    },

    init : function(param) {
        this.param = param;
        this.create();
    }
};
